package pers.vicxu.mvcrestplus.aspect;


import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Create by Vic Xu on 7/26/2018
 *
 * @author Vic Xu
 */
@Aspect
@Component
public class LogAspect {

    private final Logger logger = Logger.getLogger(LogAspect.class);

    /**
     * pers.vicxu.mvcrestplus包下所有的类方法都会被代理
     */

    @Pointcut(value = "execution(* pers.vicxu.mvcrestplus..*.*(..))")
    public void ponitCut() {

    }

    @Before(value = "ponitCut()")
    public void logBefore(JoinPoint joinPoint) {
        String start = joinPoint.getTarget().getClass().getName() + "is Starting";
        logger.info(start);
    }

    @Around(value = "ponitCut()")
    public Object logAround(ProceedingJoinPoint point) throws Throwable {
        logger.info("aop is around");
        return point.proceed();
    }

    @After(value = "ponitCut()")
    public void logAfter(JoinPoint joinPoint) {
        String end = joinPoint.getTarget().getClass().getName() + "is Ending";
        logger.info(end);
    }
}
